import cv2
from Mouse import MouseUse
from managers import WindowManager, CaptureManager
import rects
import Detection
import numpy as np
from scipy import ndimage
from numpy import *
# Object
Display = WindowManager('Display')
Display.createWindow()
Mouseusing = MouseUse('Display')
# Input
img = cv2.imread('1.jpg', 1)
img_crop = np.zeros(img.shape, np.uint8)
# Crop
while (1):
    img_copy = img.copy()
    if Mouseusing.StartFlag and not Mouseusing.FinishFlag:
        rect = [Mouseusing.get_sx(), Mouseusing.get_sy(), Mouseusing.get_ex()-Mouseusing.get_sx(), Mouseusing.get_ey()-Mouseusing.get_sy()]
        rects.outlineRect(img_copy, rect, (0, 255, 0), 3)
    Display.show(img_copy)
    cv2.waitKey(10)
    if Mouseusing.FinishFlag:
        img_crop = img[Mouseusing.get_sy():Mouseusing.get_ey(), Mouseusing.get_sx():Mouseusing.get_ex()]
        break


# Detection
while 1:
    img_th = Detection.thresh(img_crop)
    Display.show(img_th)

    k = cv2.waitKey(10)
    if k == 27:
        break

Display.destroyWindow()
